$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'bss/apcriteria/list?state=isdelno&pGuid='+ GetUrlParam("guid"),
        datatype: "json",
        colModel: [			
			{ label: 'guid', name: 'guid', index: 'guid', width: 50, key: true ,hidden: true},
			{ label: '所属项目ID', name: 'pGuid', index: 'p_guid', width: 80,hidden: true },
			{ label: '准入条件ID', name: 'pCGuid', index: 'p_c_guid', width: 80,hidden: true },
			{ label: '序号', name: 'pCNum', index: 'p_c_num', width: 20 },
			{ label: '准入条件', name: 'pCCriteria', index: 'p_c_criteria', width: 80 }, 			
			{ label: '所属章节序号', name: 'pCChapter', index: 'p_c_chapter', width: 80 }, 			
			{ label: '所属章节名称', name: 'pCName', index: 'p_c_name', width: 80 }, 			
			{ label: '数据状态', name: 'pCDatastate', index: 'p_c_datastate', width: 80 ,hidden: true}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });

    $.when( getdatadictionary("progect_type_smal_"+ GetUrlParam("ptype"))).done($("#jqGrid1").jqGrid({
        url: baseURL + 'api/bentrycriteria/listselect?ptype='+GetUrlParam("ptype")+"&pguid="+GetUrlParam("guid"),
        datatype: "json",
        colModel: [
            {label: 'guid', name: 'guid', index: 'guid', width: 50, key: true, hidden: true},

            {label: '序号', name: 'eCNum', index: 'e_c_num', width: 80},
            {
                label: '项目子类', name: 'eCSaml', index: 'e_c_saml', width: 150,
                formatter: function (cellvalue, options, rowObject) {
                    for (d in progect_type_smal) {
                        if (cellvalue == progect_type_smal[d].dKey) return progect_type_smal[d].dValue;
                    }
                }
            },
            {label: '准入条件', name: 'eCCriteria', index: 'e_c_criteria', width: 300},
            {label: '所属章节序号', name: 'eCChapter', index: 'e_c_chapter', width: 200},
            {label: '所属章节名称', name: 'eCName', index: 'e_c_name', width: 200}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager1",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid1").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    }));

});
var  progect_type_smal=null;
function getdatadictionary(sss)
{

    $.get(baseURL + "api/bdatadictionary/select?d_code="+sss, function(r){
          progect_type_smal=r.returnlist;
        vm.progect_type_smal=progect_type_smal;



    });
}
function getSelectedRows1() {
    var grid = $("#jqGrid1");
    var rowKey = grid.getGridParam("selrow");
    if (!rowKey) {
        alert("请选择一条记录");
        return;
    }

    return grid.getGridParam("selarrrow");
}
var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
        q:{
            eCSaml:null
        },
		aPCriteria: {},
        progect_type_smal:{}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.aPCriteria = {};
            vm.progect_type_smal=progect_type_smal;
		},
		update: function (event) {
			var guid = getSelectedRow();
			if(guid == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(guid)
		},
		saveOrUpdate: function (event) {
			var url = vm.aPCriteria.guid == null ? "bss/apcriteria/save" : "bss/apcriteria/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.aPCriteria),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var guids = getSelectedRows();
			if(guids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "bss/apcriteria/delete",
                    contentType: "application/json",
				    data: JSON.stringify(guids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(guid){
			$.get(baseURL + "bss/apcriteria/info/"+guid, function(r){
                vm.aPCriteria = r.aPCriteria;
            });
		},
        selectcrteri: function (event) {
            var guids = getSelectedRows1();
            if(guids == null){
                return ;
            }
            var guid= (GetUrlParam("guid"));
            var url = "bss/apcriteria/saveselect/"+guid ;
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(guids),

                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(index){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });

        },
        reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{

                page:page
            }).trigger("reloadGrid");
		},
        reloadcrteri: function (event) {

            var page = $("#jqGrid1").jqGrid('getGridParam','page');
            $("#jqGrid1").jqGrid('setGridParam',{
                postData: {
                    'eCSaml': vm.q.eCSaml

                },
                page:page
            }).trigger("reloadGrid");
        }
	}
});